/**
 * Selling Partner API for Product Type Definitions
 * The Selling Partner API for Product Type Definitions provides programmatic access to attribute and data requirements for product types in the Amazon catalog. Use this API to return the JSON Schema for a product type that you can then use with other Selling Partner APIs, such as the Selling Partner API for Listings Items, the Selling Partner API for Catalog Items, and the Selling Partner API for Feeds (for JSON-based listing feeds).  For more information, see the [Product Type Definitions API Use Case Guide](doc:product-type-api-use-case-guide).
 *
 * The version of the OpenAPI document: 2020-09-01
 *
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 *
 */

import { ApiClient } from '../ApiClient.js'
import { ErrorList } from '../model/ErrorList.js'
import { ProductTypeDefinition } from '../model/ProductTypeDefinition.js'
import { ProductTypeList } from '../model/ProductTypeList.js'
import { SuperagentRateLimiter } from '../../../helper/SuperagentRateLimiter.mjs'
import { DefaultRateLimitFetcher } from '../../../helper/DefaultRateLimitFetcher.mjs'

/**
* Definitions service.
* @module producttypedefinitions_v2020_09_01/api/DefinitionsApi
* @version 2020-09-01
*/
export class DefinitionsApi {
  // Private member stores the default rate limiters
  #defaultRateLimiterMap

  /**
    * Constructs a new DefinitionsApi.
    * @alias module:producttypedefinitions_v2020_09_01/api/DefinitionsApi
    * @class
    * @param {ApiClient} [apiClient] Optional API client implementation to use,
    * default to {@link ApiClient#instance} if unspecified.
    */
  constructor (apiClient) {
    this.apiClient = apiClient || ApiClient.instance
    this.initializeDefaultRateLimiterMap()
  }

  /**
     * Initialize rate limiters for API operations
     */
  initializeDefaultRateLimiterMap () {
    this.#defaultRateLimiterMap = new Map()
    const defaultRateLimitFetcher = new DefaultRateLimitFetcher()
    const operations = [
      'DefinitionsApi-getDefinitionsProductType',
      'DefinitionsApi-searchDefinitionsProductTypes'
    ]

    for (const operation of operations) {
      const config = defaultRateLimitFetcher.getLimit(operation)
      this.#defaultRateLimiterMap.set(operation, new SuperagentRateLimiter(config))
    }
  }

  /**
     * Get rate limiter for a specific operation
     * @param {String} operation name
     */
  getRateLimiter (operation) {
    return this.#defaultRateLimiterMap.get(operation)
  }

  /**
     * Retrieve an Amazon product type definition.  **Usage Plans:**  | Plan type | Rate (requests per second) | Burst | | ---- | ---- | ---- | |Default| 5 | 10 | |Selling partner specific| Variable | Variable |  The x-amzn-RateLimit-Limit response header returns the usage plan rate limits that were applied to the requested operation. Rate limits for some selling partners will vary from the default rate and burst shown in the table above. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](doc:usage-plans-and-rate-limits-in-the-sp-api).
     * @param {String} productType The Amazon product type name.
     * @param {[String]} marketplaceIds A comma-delimited list of Amazon marketplace identifiers for the request. Note: This parameter is limited to one marketplaceId at this time.
     * @param {Object} opts Optional parameters
     * @param {String} opts.sellerId A selling partner identifier. When provided, seller-specific requirements and values are populated within the product type definition schema, such as brand names associated with the selling partner.
     * @param {String} opts.productTypeVersion The version of the Amazon product type to retrieve. Defaults to \&quot;LATEST\&quot;,. Prerelease versions of product type definitions may be retrieved with \&quot;RELEASE_CANDIDATE\&quot;. If no prerelease version is currently available, the \&quot;LATEST\&quot; live version will be provided. (default to &#39;LATEST&#39;)
     * @param {String} opts.requirements The name of the requirements set to retrieve requirements for. (default to &#39;LISTING&#39;)
     * @param {String} opts.requirementsEnforced Identifies if the required attributes for a requirements set are enforced by the product type definition schema. Non-enforced requirements enable structural validation of individual attributes without all the required attributes being present (such as for partial updates). (default to &#39;ENFORCED&#39;)
     * @param {String} opts.locale Locale for retrieving display labels and other presentation details. Defaults to the default language of the first marketplace in the request. (default to &#39;DEFAULT&#39;)
     * @return {Promise<ProductTypeDefinition>}
     */
  getDefinitionsProductTypeWithHttpInfo (productType, marketplaceIds, opts) {
    opts = opts || {}
    const postBody = null

    // verify the required parameter 'productType' is set
    if (productType === undefined || productType === null) {
      throw new Error("Missing the required parameter 'productType' when calling getDefinitionsProductType")
    }

    // verify the required parameter 'marketplaceIds' is set
    if (marketplaceIds === undefined || marketplaceIds === null) {
      throw new Error("Missing the required parameter 'marketplaceIds' when calling getDefinitionsProductType")
    }

    const pathParams = {
      productType
    }
    const queryParams = {
      sellerId: opts.sellerId,
      marketplaceIds: this.apiClient.buildCollectionParam(marketplaceIds, 'csv'),
      productTypeVersion: opts.productTypeVersion,
      requirements: opts.requirements,
      requirementsEnforced: opts.requirementsEnforced,
      locale: opts.locale
    }
    const headerParams = {
    }
    const formParams = {
    }

    const contentTypes = []
    const accepts = ['application/json']
    const returnType = ProductTypeDefinition

    return this.apiClient.callApi('DefinitionsApi-getDefinitionsProductType',
      '/definitions/2020-09-01/productTypes/{productType}', 'GET',
      pathParams, queryParams, headerParams, formParams, postBody,
      contentTypes, accepts, returnType, this.getRateLimiter('DefinitionsApi-getDefinitionsProductType')
    )
  }

  /**
     * Retrieve an Amazon product type definition.  **Usage Plans:**  | Plan type | Rate (requests per second) | Burst | | ---- | ---- | ---- | |Default| 5 | 10 | |Selling partner specific| Variable | Variable |  The x-amzn-RateLimit-Limit response header returns the usage plan rate limits that were applied to the requested operation. Rate limits for some selling partners will vary from the default rate and burst shown in the table above. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](doc:usage-plans-and-rate-limits-in-the-sp-api).
     * @param {String} productType The Amazon product type name.
     * @param {[String]} marketplaceIds A comma-delimited list of Amazon marketplace identifiers for the request. Note: This parameter is limited to one marketplaceId at this time.
     * @param {Object} opts Optional parameters
     * @param {String} opts.sellerId A selling partner identifier. When provided, seller-specific requirements and values are populated within the product type definition schema, such as brand names associated with the selling partner.
     * @param {String} opts.productTypeVersion The version of the Amazon product type to retrieve. Defaults to \&quot;LATEST\&quot;,. Prerelease versions of product type definitions may be retrieved with \&quot;RELEASE_CANDIDATE\&quot;. If no prerelease version is currently available, the \&quot;LATEST\&quot; live version will be provided. (default to &#39;LATEST&#39;)
     * @param {String} opts.requirements The name of the requirements set to retrieve requirements for. (default to &#39;LISTING&#39;)
     * @param {String} opts.requirementsEnforced Identifies if the required attributes for a requirements set are enforced by the product type definition schema. Non-enforced requirements enable structural validation of individual attributes without all the required attributes being present (such as for partial updates). (default to &#39;ENFORCED&#39;)
     * @param {String} opts.locale Locale for retrieving display labels and other presentation details. Defaults to the default language of the first marketplace in the request. (default to &#39;DEFAULT&#39;)
     * @return {Promise<ProductTypeDefinition>}
     */
  getDefinitionsProductType (productType, marketplaceIds, opts) {
    return this.getDefinitionsProductTypeWithHttpInfo(productType, marketplaceIds, opts)
      .then(function (response_and_data) {
        return response_and_data.data
      })
  }

  /**
     * Search for and return a list of Amazon product types that have definitions available.  **Usage Plans:**  | Plan type | Rate (requests per second) | Burst | | ---- | ---- | ---- | |Default| 5 | 10 | |Selling partner specific| Variable | Variable |  The x-amzn-RateLimit-Limit response header returns the usage plan rate limits that were applied to the requested operation. Rate limits for some selling partners will vary from the default rate and burst shown in the table above. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](doc:usage-plans-and-rate-limits-in-the-sp-api).
     * @param {[String]} marketplaceIds A comma-delimited list of Amazon marketplace identifiers for the request.
     * @param {Object} opts Optional parameters
     * @param {[String]} opts.keywords A comma-delimited list of keywords to search product types. **Note:** Cannot be used with &#x60;itemName&#x60;.
     * @param {String} opts.itemName The title of the ASIN to get the product type recommendation. **Note:** Cannot be used with &#x60;keywords&#x60;.
     * @param {String} opts.locale The locale for the display names in the response. Defaults to the primary locale of the marketplace.
     * @param {String} opts.searchLocale The locale used for the &#x60;keywords&#x60; and &#x60;itemName&#x60; parameters. Defaults to the primary locale of the marketplace.
     * @return {Promise<ProductTypeList>}
     */
  searchDefinitionsProductTypesWithHttpInfo (marketplaceIds, opts) {
    opts = opts || {}
    const postBody = null

    // verify the required parameter 'marketplaceIds' is set
    if (marketplaceIds === undefined || marketplaceIds === null) {
      throw new Error("Missing the required parameter 'marketplaceIds' when calling searchDefinitionsProductTypes")
    }

    const pathParams = {
    }
    const queryParams = {
      keywords: this.apiClient.buildCollectionParam(opts.keywords, 'csv'),
      marketplaceIds: this.apiClient.buildCollectionParam(marketplaceIds, 'csv'),
      itemName: opts.itemName,
      locale: opts.locale,
      searchLocale: opts.searchLocale
    }
    const headerParams = {
    }
    const formParams = {
    }

    const contentTypes = []
    const accepts = ['application/json']
    const returnType = ProductTypeList

    return this.apiClient.callApi('DefinitionsApi-searchDefinitionsProductTypes',
      '/definitions/2020-09-01/productTypes', 'GET',
      pathParams, queryParams, headerParams, formParams, postBody,
      contentTypes, accepts, returnType, this.getRateLimiter('DefinitionsApi-searchDefinitionsProductTypes')
    )
  }

  /**
     * Search for and return a list of Amazon product types that have definitions available.  **Usage Plans:**  | Plan type | Rate (requests per second) | Burst | | ---- | ---- | ---- | |Default| 5 | 10 | |Selling partner specific| Variable | Variable |  The x-amzn-RateLimit-Limit response header returns the usage plan rate limits that were applied to the requested operation. Rate limits for some selling partners will vary from the default rate and burst shown in the table above. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](doc:usage-plans-and-rate-limits-in-the-sp-api).
     * @param {[String]} marketplaceIds A comma-delimited list of Amazon marketplace identifiers for the request.
     * @param {Object} opts Optional parameters
     * @param {[String]} opts.keywords A comma-delimited list of keywords to search product types. **Note:** Cannot be used with &#x60;itemName&#x60;.
     * @param {String} opts.itemName The title of the ASIN to get the product type recommendation. **Note:** Cannot be used with &#x60;keywords&#x60;.
     * @param {String} opts.locale The locale for the display names in the response. Defaults to the primary locale of the marketplace.
     * @param {String} opts.searchLocale The locale used for the &#x60;keywords&#x60; and &#x60;itemName&#x60; parameters. Defaults to the primary locale of the marketplace.
     * @return {Promise<ProductTypeList>}
     */
  searchDefinitionsProductTypes (marketplaceIds, opts) {
    return this.searchDefinitionsProductTypesWithHttpInfo(marketplaceIds, opts)
      .then(function (response_and_data) {
        return response_and_data.data
      })
  }
}
